Stygian = Stygian or {}
Stygian.chat = Stygian.chat or {}
Stygian.chat.fontSize = Stygian.chat.fontSize or 9
Stygian.chat.fontWidth, Stygian.chat.fontHeight = calcFontSize(Stygian.chat.fontSize)
mainWidth, mainHeight = getMainWindowSize()
Stygian.chat.width = 340
Stygian.chat.height = Stygian.chat.fontHeight * 35
Stygian.chat.wordwrap = (Stygian.chat.width / Stygian.chat.fontWidth) - 1

function Stygian.chat.posY()
  return Stygian.map.height + 26
end

function Stygian.chat.posX()
  return mainWidth - Stygian.chat.width
end

chatTable = {
        "All",
        "Tells",
        "City",
        "Guild",
        "Market",
        }
 
Stygian.chat.tabWidth, Stygian.chat.tabHeight = math.floor( Stygian.chat.width / table.getn( chatTable ) ), 25
Stygian.chat.tabPosX, Stygian.chat.tabPosY = Stygian.chat.posX(), Stygian.chat.posY() - 25
 
-- Functions
function Stygian_chatCreate ()
        local startX = Stygian.chat.tabPosX
        for _,v in ipairs( chatTable ) do
                local tab = "tab" .. v
                createLabel( tab, startX, Stygian.chat.tabPosY, Stygian.chat.tabWidth, Stygian.chat.tabHeight, 0 )
                resizeWindow( tab, Stygian.chat.tabWidth, Stygian.chat.tabHeight )
                setLabelClickCallback( tab, "switchchat", v )
                echo( tab, [[<center><font color="white">]] .. v .. [[</font></center></b></p>]] )
                moveWindow( tab, startX, Stygian.chat.tabPosY )
                startX = startX + Stygian.chat.tabWidth
 
                local chat = "chat" .. v
                createMiniConsole( chat, Stygian.chat.posX(), Stygian.chat.posY(), Stygian.chat.width, Stygian.chat.height )
                resizeWindow( chat, Stygian.chat.width, Stygian.chat.height )
                setWindowWrap( chat, Stygian.chat.wordwrap )
                setMiniConsoleFontSize( chat, Stygian.chat.fontSize )
                setBackgroundColor( chat, 0, 0, 0, 0 )
                moveWindow( chat, Stygian.chat.posX(), Stygian.chat.posY() )
                hideWindow( chat )
        end
        Stygian.chat.currentTab = "none"
        switchchat( "All" )
end
 
function switchchat ( chat )
        local o_c = "chat" .. Stygian.chat.currentTab
        local o_t = "tab" .. Stygian.chat.currentTab
        local n_c = "chat" .. chat
        local n_t = "tab" .. chat
        if Stygian.chat.currentTab ~= chat then
                hideWindow( o_c )
                showWindow( n_c )
                Stygian.chat.currentTab = chat
                setBackgroundColor( o_t, 0, 0, 0, 0 )
                setBackgroundColor( n_t, 100, 100, 100, 125 )
        end
end

function Stygian_chatResize()
  Stygian.chat.fontWidth, Stygian.chat.fontHeight = calcFontSize(Stygian.chat.fontSize)
  mainWidth, mainHeight = getMainWindowSize()
  Stygian.chat.height = Stygian.chat.fontHeight * 35
  Stygian.chat.wordwrap = (Stygian.chat.width / Stygian.chat.fontWidth) - 1
  Stygian.chat.tabWidth, Stygian.chat.tabHeight = math.floor( Stygian.chat.width / table.getn( chatTable ) ), 25
  Stygian.chat.tabPosX, Stygian.chat.tabPosY = Stygian.chat.posX(), Stygian.chat.posY() - 25
  Stygian_chatCreate()
end 

if not Stygian.chat.initialized then
	Stygian_chatCreate()
	Stygian.chat.initialized = true
end
